<template>
    <el-container class="index-con">
      <el-aside :class="showclass">
        <!-- 左侧边菜单 -->
        <leftnav @toggle="toggle($event)"></leftnav>
      </el-aside>
      <el-container class="main-con">
        <el-header class="index-header">
          <!-- 上方导航栏 -->
          <topnav :breadList="breadList" ></topnav>
        </el-header>
        <el-main class="index-main">
          <!-- 路由占位符 当有子路由时将子路由对应的页面替换该占位 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
</template>
<script>
import leftnav from './common/leftnav';
import topnav from './common/topnav';
export default {
  name: 'index',
  data() {
    return {
      showclass: 'aside',
      breadList:[]
    }
  },
  // 注册组件
  components: {
    topnav,
    leftnav
  },
  methods: {
    toggle(val){
      if (val) {
        this.showclass = 'asideshow'
      } else {
        setTimeout(() => {
          this.showclass = 'aside'
        }, 300)
      }
    }
  },
  created() {
    this.$root.Bus.$on('initBread', breadList=>{
      this.breadList = breadList
    });
  },
  beforeCreate() {
    this.$store.commit('set_token', localStorage.getItem('token'));
    this.$store.commit('set_user', JSON.parse(localStorage.getItem('user')));
    this.$store.commit('set_projectId', JSON.parse(localStorage.getItem('user')).lastProject);
    this.$store.commit('set_permissions', JSON.parse(localStorage.getItem('user')).permissions)
  }
}
</script>
<style >
.index-con {
  height: 100%;
  width: 100%;
  box-sizing: border-box;
}
.aside {
  width: 48px !important;
  height: 100%;
  background-color: #334157;
  margin: 0px;
}
.asideshow {
  width: 200px !important;
  height: 100%;
  background-color: #334157;
  margin: 0px;
}
.index-header{
  max-height: 40px;
}
.main-card{
  min-height: 100%;
  border: none;
}
</style>
